#include "CompBioTools.hh"

char GetBase(int idx){
  switch(idx){
  case 0 : return('A');
  case 1 : return('C');
  case 2 : return('G');
  case 3 : return('T');
  }
}


void GetSeqForIdx(int idx,string &Seq){

  // ACTA
  int D3 = idx /(4*4*4);
  idx = idx - (D3*(4*4*4));

  int D2 = idx /(4*4);
  idx = idx - (D2*4*4);

  int D1 = idx /(4);
  idx = idx - (D1*4);

  int D0 = idx;

  Seq=GetBase(D3);
  Seq+=GetBase(D2);
  Seq+=GetBase(D1);
  Seq+=GetBase(D0);
}


//--------------------------------------
// * main
//--------------------------------------
// 
int main(int argc,char** argv)
{
  if (argc< 2){
	 printf("
      kjd-run-abundant cutoff FONPath

      Runs a cluster job of distributed atlas-abundant-mer jobs. 

      ");
	 exit(1);
  }
  string cutoff = argv[1];
  string FONPath = argv[2]; 

  for(int idx = 0;idx < 128;idx++){

	 string Prefix;
	 //GetSeqForIdx(idx,Prefix);
	 //cout<<Prefix<<endl;

	 string OutPath = "/users/pipeline/p-atlas/atlas/kdurbin/merfreq/mer"+itoa(idx);

	 string cmd = "bsub -sp 60 -R \"type==LINUX\" \"/home/hgsc/user/kdurbin/bin/atlas-abundant-mer -F "+FONPath+" -R "+cutoff;
	 cmd += " -s "+itoa(idx)+" -o "+OutPath+" ";
	 cmd += " -d "+OutPath+".dist "; 
	 cmd += " > /users/pipeline/p-atlas/atlas/kdurbin/merfreq/mer"+itoa(idx)+".stdout";
	 cmd += " 2>&1 \"";

	 cout<<cmd<<endl;
	 system(cmd.c_str());
  }
}
